package com.tools.developer;

import android.app.Activity;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Bundle;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tools.developer.util.KLog;

public class QzoneActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_qzone);

		WebView qzoneWeb = (WebView) findViewById(R.id.qzone_webview);
		qzoneWeb.getSettings().setJavaScriptEnabled(true);
		qzoneWeb.addJavascriptInterface(new Object() { // 添加javascript可调用的接口
					public void clickOnAndroid() {
						
					}
				}, "demo");

		qzoneWeb.setWebViewClient(new QzoneWebViewClient());
	}

	private class QzoneWebViewClient extends WebViewClient {

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			KLog.d("Redirect URL: " + url);
			return true;
		}

		@Override
		public void onReceivedError(WebView view, int errorCode,
				String description, String failingUrl) {
			super.onReceivedError(view, errorCode, description, failingUrl);
		}

		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			KLog.d("onPageStarted URL: " + url);
			super.onPageStarted(view, url, favicon);
		}

		@Override
		public void onPageFinished(WebView view, String url) {
			KLog.d("onPageFinished URL: " + url);
		}

		public void onReceivedSslError(WebView view, SslErrorHandler handler,
				SslError error) {
			handler.proceed();
		}

	}
}
